package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.mapper.EduTeacherMapper;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-02-24
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {
    // 热门讲师
    @Override
    public List<EduTeacher> gethotTeacher() {
        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 4");
        return baseMapper.selectList(wrapper);
    }

    // 前台讲师分页
    @Override
    public Map<String, Object> getTeacherList(Page<EduTeacher> eduTeacherpage) {

        baseMapper.selectPage(eduTeacherpage, null);
        List<EduTeacher> records = eduTeacherpage.getRecords();
        long current = eduTeacherpage.getCurrent();
        long size = eduTeacherpage.getSize();
        long total = eduTeacherpage.getTotal();
        boolean hasNext = eduTeacherpage.hasNext();
        boolean hasPrevious = eduTeacherpage.hasPrevious();

        HashMap<String, Object> map = new HashMap<>();

        map.put("records", records);
        map.put("current", current);
        map.put("size", size);

        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;
    }
}
